from loguru import logger

log_handler = logger.add("/tmp/test.log")
logger.debug("This is a debug message 1")

# 移除日志
logger.remove(log_handler)
log2_handler = logger.add("/tmp/test.log")
logger.debug("This is a debug message 2")

""" 运行2次结果
# python3 3.1_loguru_add_追加日志到文件.py
2025-07-02 15:24:31.501 | DEBUG    | __main__:<module>:4 - This is a debug message 1
2025-07-02 15:24:31.503 | DEBUG    | __main__:<module>:9 - This is a debug message 2

# python3 3.1_loguru_add_追加日志到文件.py
2025-07-02 15:25:00.848 | DEBUG    | __main__:<module>:4 - This is a debug message 1
2025-07-02 15:25:00.850 | DEBUG    | __main__:<module>:9 - This is a debug message 2

# cat /tmp/test.log 
2025-07-02 15:24:31.501 | DEBUG    | __main__:<module>:4 - This is a debug message 1
2025-07-02 15:24:31.503 | DEBUG    | __main__:<module>:9 - This is a debug message 2
2025-07-02 15:25:00.848 | DEBUG    | __main__:<module>:4 - This is a debug message 1
2025-07-02 15:25:00.850 | DEBUG    | __main__:<module>:9 - This is a debug message 2

结论:
loguru默认是追加日志到文件
"""